package com.ayou.eggguard.farm.service.impl;

import com.ayou.eggguard.farm.mapper.ChickenShedMapper;
import com.ayou.eggguard.farm.pojo.ChickenShed;
import com.ayou.eggguard.farm.service.ChickenShedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ChickenShedServiceImpl implements ChickenShedService {

    @Autowired
    private ChickenShedMapper chickenShedMapper;

    @Override
    public List<List<Object>> getShedAlarmRate() {

        List<ChickenShed> sheds=chickenShedMapper.getAllSheds();
        List<List<Object>> alarmRate=new ArrayList<>();
        for(ChickenShed shed:sheds){
            List<Object> tmp=new ArrayList<>();
            tmp.add(shed.getLon());
            tmp.add(shed.getLat());
            double rate= ((double)shed.getDiCount())/(shed.getShedArea()*shed.getDensity());
            BigDecimal value = new BigDecimal(rate);
            BigDecimal formattedValue = value.setScale(5, RoundingMode.HALF_UP);
            tmp.add(formattedValue);
            tmp.add(shed.getCoopNumber());
            alarmRate.add(tmp);
        }
        return alarmRate;
    }
}
